package com.newcoin.chat.dao;

import com.newcoin.chat.beans.entity.UserEntity;
import com.newcoin.chat.beans.vo.UserVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

@Component
public interface UserDao {
    /**
     * 是否授权
     *
     * @param superUserId
     * @return
     */
    @Select("SELECT id,account,nickname,head_img_path AS headImgPath,state,sex,province,city,area_county AS areaCounty,circle_of_friends_img AS circleOfFriendsImg,qr_code AS qrcode FROM chat_user WHERE super_user_id=#{superUserId}")
    UserVo whetherAuthorized(@Param("superUserId") long superUserId);

    /**
     * 授权 同步信息
     *
     * @param userEntity
     * @return
     */
    int authorized(UserEntity userEntity);

    /**
     * 保存二维码信息
     *
     * @param userId
     * @param code
     * @return
     */
    @Update("UPDATE chat_user SET qr_code=#{QRCode} WHERE id=#{userId}")
    int saveQRCode(@Param("userId") long userId, @Param("QRCode") String code);

    /**
     * 用户详细信息根据ID
     *
     * @param userId
     * @return
     */
    @Select("SELECT id,nickname,head_img_path AS headImgPath FROM chat_user WHERE id=#{userId}")
    UserVo getUserInfoById(@Param("userId") long userId);

    /**
     * 修改头像
     *
     * @param userId
     * @param head
     * @return
     */
    @Update("UPDATE chat_user SET head_img_path=#{head} WHERE id=#{userId}")
    int updateUserHead(@Param("userId") Long userId, @Param("head") String head);

    /**
     * 修改昵称
     *
     * @param userId
     * @param nickname
     * @return
     */
    @Update("UPDATE chat_user SET nickname=#{nickname} WHERE id=#{userId}")
    int updateUserNickname(@Param("userId") Long userId, @Param("nickname") String nickname);
}
